<template>
  <div class="">
    <form>
      <!--          身份验证信息-->
      <div class="border-bottom mb-4">
        <label class="" style="color: #0f5da2;font-size: 20px;font-weight: bold">身份验证信息</label>
      </div>
      <div class="form-group">
        <label for="inputIfcheck">身份审核情况</label>
        <input type="email" class="form-control " id="inputIfcheck" v-model="PersonIdentity.ifcheck" readonly="readonly">
      </div>
      <div class="form-row">
        <div class="form-group col-md-4">
          <label for="inputIdentity">身份</label>
          <select id="inputIdentity" class="form-control" v-model="PersonIdentity.identity" >
            <option value="-1" disabled selected hidden>请选择</option>
            <option value="0" style="color: black;">学生</option>
            <option value="1" style="color: black;">已毕业的学长学姐</option>
            <option value="2" style="color: black;">老师</option>
          </select>
        </div>
        <div class="form-group col-md-4">
          <label for="inputSno">学号/教师编号</label>
          <input type="text" class="form-control" id="inputSno" v-model="PersonIdentity.sno" :readonly="status==1?'readonly':false">
        </div>
        <div class="form-group col-md-4">
          <label for="inputTrueName">真实姓名</label>
          <input type="text" class="form-control" id="inputTrueName" v-model="PersonIdentity.true_name" :readonly="status==1?'readonly':false">
        </div>
      </div>
      <div class="form-group">
        <label for="inputFaculty">院系</label>
        <select id="inputFaculty" class="form-control" v-model="PersonIdentity.faculty">
          <option selected>信息科学与技术学院</option>
          <option>人文与传播学院</option>
          <option>法学院</option>
          <option>英语语言文化学院</option>
          <option>日本语言与文化学院</option>
          <option>设计与创意学院</option>
          <option>音乐系</option>
          <option>国际商务学院</option>
          <option>会计与金融学院</option>
          <option>管理学院</option>
          <option>机电工程学院</option>
          <option>土木工程学院</option>
          <option>建筑学院</option>
          <option>环境科学与工程学院</option>
        </select>
      </div>
      <div class="form-row" v-show="identity_num == 0 || identity_num == 1">
        <div class="form-group col-md-6">
          <label for="inputGrade">年级</label>
          <input type="text" class="form-control" id="inputGrade" v-model="PersonIdentity.grade">
        </div>
        <div class="form-group col-md-6">
          <label for="inputSubject">专业班级</label>
          <input type="text" class="form-control" id="inputSubject" v-model="PersonIdentity.subject">
        </div>
      </div>
      <div class="btn-group" role="group">
        <button type="submit" class="btn mt-4" style="background-color: #B7C1AC;color: white"  @click="updateSave">保存信息</button>
      </div>
      <div class="btn-group ml-4" role="group">
        <button type="submit" class="btn mt-4" style="background-color: #B7C1AC;color: white" @click="clearInput">重&nbsp;&nbsp;置</button>
      </div>
    </form>
  </div>
</template>

<script>
import {getUser_Identity,updateUserIdentityByUser} from '@/api/User'


export default {
  name: "person_identity",
  data(){
    return{
      PersonIdentity:{
        ifcheck:'',
        identity:'',
        sno:'',
        true_name:'',
        faculty:'',
        grade:'',
        subject:'',
      },
      status:0,
      identity_num:'',




    }
  },

  methods:{
    // 获取当前用户的身份验证信息
    init(){
      getUser_Identity({
        // token: window.sessionStorage.getItem('token')
      }).then(res=>{
        this.PersonIdentity.sno=res.data.sno;
        this.PersonIdentity.true_name=res.data.true_name;
        this.PersonIdentity.faculty=res.data.faculty;
        this.PersonIdentity.grade=res.data.grade;
        this.PersonIdentity.subject=res.data.subject;
        this.identity_num=res.data.identity;

        this.PersonIdentity.identity=res.data.identity;

        if(res.data.ifcheck==0) {
          this.PersonIdentity.ifcheck='未审核';
        } else if(res.data.ifcheck==2){
          this.PersonIdentity.ifcheck='审核不通过';
        }else if(res.data.ifcheck==1){
          this.PersonIdentity.ifcheck='审核已通过';
        }
        this.check= res.data.ifcheck;
        //已经审核通过
        if(this.check==1){
          this.status=1;
        }
        else{
          //审核不通过和未审核
          this.status=0;
        }
      });

    },
  //  清空输入框
    clearInput(){
      this.PersonIdentity.sno="";
      this.PersonIdentity.true_name="";
      this.PersonIdentity.faculty="";
      this.PersonIdentity.grade="";
      this.PersonIdentity.subject="";
    },
  //  提交（更改）验证信息
    async updateSave(){

      if(this.PersonIdentity.identity.length==0){
        this.$msg.warning('请选择身份！');
        return false;
      }
      if(this.PersonIdentity.sno.length==0){
        this.$msg.warning('请输入学号或教师编号！！');
        return false;
      }
      if(this.PersonIdentity.true_name.length==0){
        this.$msg.warning('请输入真实姓名！');
        return false;
      }
      if(this.PersonIdentity.faculty.length==0){
        this.$msg.warning('请选择院系！');
        return false;
      }
      if(this.PersonIdentity.grade.length==0){
        this.$msg.warning('请输入年级！');
        return false;
      }
      if(this.PersonIdentity.subject.length==0){
        this.$msg.warning('请输入专业班级！');
        return false;
      }

      updateUserIdentityByUser({
        PersonIdentity:this.PersonIdentity,
        // token: window.sessionStorage.getItem('token')
      }).then(res=>{
        if(res.data.result==2){
          this.$msg.success('更新成功！');
        }
        else if(res.data.result==0){
          this.$msg.error('更新失败！');
        }
        //修改了内容，审核情况变为审核中
        else if(res.data.result==1){
          window.sessionStorage.setItem('check',res.data.ifcheck);
          window.sessionStorage.setItem('currentIdentity',res.data.identity);
          this.$msg.success('更新成功！');
          this.$router.go(0);
        }
        else{
          this.$msg.error('更新失败！');
        }
      })


    },

  },
  created() {
    let _this=this;

    _this.init();
  },




}
</script>

<style scoped>
.form-group{
  padding:6px;
}
</style>
